import request from '@/utils/request'

// 查询核心人员信息列表
export function listCustomer(query) {
  return request({
    url: '/ry/customer/customer/list',
    method: 'get',
    params: query
  })
}

// 查询核心人员信息详细
export function getCustomer(id) {
  return request({
    url: '/ry/customer/customer/' + id,
    method: 'get'
  })
}

// 新增核心人员信息
export function addCustomer(data) {
  return request({
    url: '/ry/customer/customer',
    method: 'post',
    data: data
  })
}

// 修改核心人员信息
export function updateCustomer(data) {
  return request({
    url: '/ry/customer/customer',
    method: 'put',
    data: data
  })
}

// 删除核心人员信息
export function delCustomer(id) {
  return request({
    url: '/ry/customer/customer/' + id,
    method: 'delete'
  })
}

// 批量AI分析客户（流式返回）
export async function streamBatchAnalyzeCustomerAI(data, signal) {
  const token = localStorage.getItem('Admin-Token') || '';
  const response = await fetch(process.env.VUE_APP_BASE_API + '/push/AI/analyzeListUsers', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + token
    },
    body: JSON.stringify({
      customerIds: data.customerIds,
      prompt: data.prompt,
      modelName: data.aiModelName
    }),
    signal: signal
  });

  if (!response.body || response.status !== 200) {
    throw new Error('AI接口异常或未返回流式内容');
  }

  return response.body.getReader();
}
